<?php
include_once("admin.inc.php");
$act = get_param("action");
$jobsModel = load_model("jobs");

switch($act):
case "jobs":
	$list = $jobsModel->get_jobs();
	$smarty->assign('list', $list);
	$smarty->display('admin/jobs.html');
break;
case "addJobs":
	if( get_param('name') ){
		$data = get_data();
		$data['addtime'] = time();
		$data['endtime'] = strtotime($data['endtime']);
		$rs = $jobsModel->add_jobs($data);
		$state = $rs>0 ? 'SUCCESS' : 'FAILED '.$jobsModel->get_error();
		msg( $state, 'jobs.php?action=jobs' );
		exit;
	}else{
		$smarty->display('admin/addJobs.html');
	}
break;
case "editJobs":
	if( get_param("name") ){
		$data = get_data();
		$data['addtime'] = time();
		$data['endtime'] = strtotime($data['endtime']);
		$rs = $jobsModel->edit_jobs($data['id'], $data);
		$state = $rs>0 ? 'SUCCESS' : 'FAILED '.$jobsModel->get_error();
		msg( $state, 'jobs.php?action=jobs' );
		exit;
	}else{
		$id = intval(get_param('id'));
		$ct = $jobsModel->get_jobs(array('id'=>$id));
		$smarty->assign('ct', $ct[0]);
		$smarty->display('admin/editJobs.html');
	}
break;
endswitch;
